package com.fangcun.controller.admin.old;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.fangcun.bean.admin.log.request.LogRequsetAllSeachRequest;
import com.fangcun.bean.sys.PageBean;
import com.fangcun.bean.sys.ResponseMsg;
import com.fangcun.common.canstant.ErrCode;
import com.fangcun.common.exception.ProException;
import com.fangcun.common.util.PublicMethod;
import com.fangcun.common.util.apiversion.ApiVersion;
import com.fangcun.service.admin.LogService;

/**
 * @作者： 陳曉鬆 @时间： 2020年6月5日 - 上午10:14:51 @description：->
 */
@RestController
@RequestMapping("/admin/{version}/auth/log")
public class LogController {

	private static Logger LOG = LoggerFactory.getLogger(LogController.class);

	@Resource(name = "logService")
	private LogService logService;

	@ApiVersion(1.0)
	@RequestMapping(value = "/logsrequestall/list")
	private ResponseMsg logsrequestalllist(@RequestBody PageBean<LogRequsetAllSeachRequest> request) {
		ResponseMsg msg = ResponseMsg.returnBeanBuild();
		try {
			msg.setData(logService.logsRequestAllList(request));
		} catch (ProException e) {
			LOG.error("-后台-全局接口访问日志出错->{},{},{}", msg.getSessionId(), e.getErrorCode(), e.getErrorMsg());
			msg.setReturnCode(e.getErrorCode()).setReturnMsg(e.getErrorMsg());
		} catch (Exception e) {
			LOG.error("-后台-全局接口访问日志异常->{},{}", msg.getSessionId(), PublicMethod.printErrorTrace(e));
			msg.setReturnCode(ErrCode.ERR.getReturnCode()).setReturnMsg(ErrCode.ERR.getReturnMsg());
		}
		return msg;
	}

	@ApiVersion(1.0)
	@RequestMapping(value = "/logsrequestall/detail")
	private ResponseMsg logsrequestalldetail(Long id) {
		ResponseMsg msg = ResponseMsg.returnBeanBuild();
		try {
			msg.setData(logService.logsRequestAllDetail(id));
		} catch (ProException e) {
			LOG.error("-后台-全局接口访问日志详情出错->{},{},{}", msg.getSessionId(), e.getErrorCode(), e.getErrorMsg());
			msg.setReturnCode(e.getErrorCode()).setReturnMsg(e.getErrorMsg());
		} catch (Exception e) {
			LOG.error("-后台-全局接口访问日志详情异常->{},{}", msg.getSessionId(), PublicMethod.printErrorTrace(e));
			msg.setReturnCode(ErrCode.ERR.getReturnCode()).setReturnMsg(ErrCode.ERR.getReturnMsg());
		}
		return msg;
	}
}
